/**
 * The data-main file to configure RequireJS. It also contains the code
 * to setup the application angular module.
 */

 (function() {
  'use strict';

  ///////////////////////////////////////////////////
  // Base path definitions
  ///////////////////////////////////////////////////
  var COMMON_BASE = '/resources/';

  ///////////////////////////////////////////////////
  // RequireJS configuration
  ///////////////////////////////////////////////////
  requirejs.config({
    paths: {
      'domReady': COMMON_BASE + 'requirejs-domready/domReady',
	  'angularJS': COMMON_BASE + 'angular/angular', 
	  'angular-ui-router': COMMON_BASE + 'ui-router/release/angular-ui-router'
    }, 
  	shim: {
      'angularJS': {
//        deps: ['jquery'],
        exports: 'angular'
      }, 
      'angular-ui-router': ['angularJS']
    }
  });

  ///////////////////////////////////////////////////
  // Application configuration
  ///////////////////////////////////////////////////
  requirejs([
    'angularJS',
    'app',
    'domReady',
    // add every individual controller file below
    // this will have to be maintained by hand
    'controllers/messaging/config',
    'controllers/messaging/common'
  ], function (angular, app, domReady) {
    app.config(['$httpProvider', '$stateProvider', '$urlRouterProvider', '$compileProvider',
        function($httpProvider, $stateProvider, $urlRouterProvider, $compileProvider) {
        $urlRouterProvider.otherwise('chat');
        $stateProvider.
         	state('chat', {
         		url: '/chat', 
         		templateUrl : 'views/chat.html', 
         		controller : 'CommonCtrl', 
         		resolve: {
        	   			config: getMessagingConfig
        			}
         	})
         	;
    }]).run(['$location', function($location) {
      // get token from somewhere
      // e.g. get it from a Java object
      // var token = tokenFromJava.getToken();
      // or get it from URL
      // var token = $location.url().....
      // then you need to give it to loginConfig
//     
//   
//
//    loginConfig.credential.usr = $location.search().token;
//    loginConfig.credential.pwd = $location.search().token;
    }]);;

    domReady(function() {
      angular.bootstrap(document, ['App']);
    });


  });
})();